﻿/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Runtime.InteropServices;
using System.Xml;
using System.IO;

namespace FaceCat
{
    /// <summary>
    /// XML界面生成类
    /// </summary>
    public class FCUIXml
    {
        /// <summary>
        /// 创建生成类
        /// </summary>
        public FCUIXml()
        {
        }

        /// <summary>
        /// 析构方法
        /// </summary>
        ~FCUIXml()
        {
            delete();
        }

        public bool m_allowName = true;

        /// <summary>
        /// 名称
        /// </summary>
        public String m_name = "";

        public static ArrayList<FCUIXml> m_nameXmls = new ArrayList<FCUIXml>();

        /// <summary>
        /// 视图列表
        /// </summary>
        public ArrayList<FCView> m_views = new ArrayList<FCView>();

        /// <summary>
        /// CSS样式
        /// </summary>
        public HashMap<String, String> m_styles = new HashMap<String, String>();

        public XmlDocument m_xmlDoc = new XmlDocument();

        /// <summary>
        /// 获取XML文档
        /// </summary>
        public virtual XmlDocument getXmlDoc()
        {
            return m_xmlDoc;
        }

        /// <summary>
        /// 设置XML文档
        /// </summary>
        public virtual void setXmlDoc(XmlDocument value)
        {
            m_xmlDoc = value;
        }

        private bool m_isDeleted = false;

        /// <summary>
        /// 获取是否被销毁
        /// </summary>
        public virtual bool isDeleted()
        {
            return m_isDeleted;
        }

        private FCNative m_native;

        /// <summary>
        /// 获取方法库
        /// </summary>
        public virtual FCNative getNative()
        {
            return m_native;
        }

        /// <summary>
        /// 设置方法库
        /// </summary>
        public virtual void setNative(FCNative value)
        {
            m_native = value;
        }

        /// <summary>
        /// 创建菜单项
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="menu">菜单</param>
        /// <param name="parentItem">父项</param>
        public virtual void createMenuItem(XmlNode node, FCMenu menu, FCMenuItem parentItem)
        {
            FCMenuItem item = new FCMenuItem();
            item.setNative(m_native);
            setAttributesBefore(node, item);
            if (parentItem != null)
            {
                parentItem.addItem(item);
            }
            else
            {
                menu.addItem(item);
            }
            if (node.ChildNodes != null && node.ChildNodes.Count > 0)
            {
                foreach (XmlNode subNode in node.ChildNodes)
                {
                    createMenuItem(subNode, menu, item);
                }
            }
            setAttributesAfter(node, item);
            onAddView(item, node);
        }

        /// <summary>
        /// 是否包含视图
        /// </summary>
        /// <param name="view">视图</param>
        /// <returns>是否包含</returns>
        public virtual bool containsView(FCView view)
        {
            foreach (FCView subView in m_views)
            {
                if (subView == view)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 创建视图
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="type">类型</param>
        /// <returns>视图</returns>
        public virtual FCView createView(XmlNode node, String type)
        {
            int typeLen = type.Length;
            switch (typeLen)
            {
                case 1:
                    {
                        if (type == "a")
                        {
                            return new FCLinkLabel();
                        }
                        break;
                    }
                case 2:
                    {
                        if (type == "th")
                        {
                            return new FCGridColumn();
                        }
                        break;
                    }
                case 3:
                    {
                        if (type == "div")
                        {
                            if (node.Attributes != null)
                            {
                                foreach (XmlAttribute attribute in node.Attributes)
                                {
                                    String name = attribute.Name.ToLower();
                                    if (name == "type")
                                    {
                                        String inputType = attribute.Value;
                                        switch (inputType)
                                        {
                                            case "layout":
                                                return new FCLayoutDiv();
                                            case "splitlayout":
                                                return new FCSplitLayoutDiv();
                                            case "tab":
                                                return new FCTabView();
                                            case "tabpage":
                                                return new FCTabPage();
                                            case "custom":
                                                return createCustomView(node);
                                        }
                                        break;
                                    }
                                }
                            }
                            return new FCDiv();
                        }
                        else if (type == "tab")
                        {
                            return new FCTabView();
                        }
                        break;
                    }
                case 4:
                    {
                        switch (type)
                        {
                            case "grid":
                                return new FCGrid();
                            case "menu":
                                return new FCMenu();
                            case "spin":
                                return new FCSpin();
                            case "tree":
                                return new FCTree();
                            case "view":
                                if (node.Attributes != null)
                                {
                                    foreach (XmlAttribute attribute in node.Attributes)
                                    {
                                        String name = attribute.Name.ToLower();
                                        if (name == "type")
                                        {
                                            String inputType = attribute.Value;
                                            switch (inputType)
                                            {
                                                case "layout":
                                                    return new FCLayoutDiv();
                                                case "splitlayout":
                                                    return new FCSplitLayoutDiv();
                                                case "tab":
                                                    return new FCTabView();
                                                case "tabpage":
                                                    return new FCTabPage();
                                                case "button":
                                                    return new FCButton();
                                                case "checkbox":
                                                    return new FCCheckBox();
                                                case "datetime":
                                                    return new FCDateTimePicker();
                                                case "radio":
                                                    return new FCRadioButton();
                                                case "range":
                                                    return new FCSpin();
                                                case "text":
                                                    return new FCTextBox();
                                                case "custom":
                                                    return createCustomView(node);
                                            }
                                            break;
                                        }
                                    }
                                }
                                return new FCDiv();
                        }
                        break;
                    }
                case 5:
                    {
                        switch (type)
                        {
                            case "chart":
                                return new FCChart();
                            case "table":
                                return new FCGrid();
                            case "input":
                                if (node.Attributes != null)
                                {
                                    foreach (XmlAttribute attribute in node.Attributes)
                                    {
                                        String name = attribute.Name.ToLower();
                                        if (name == "type")
                                        {
                                            String inputType = attribute.Value;
                                            switch (inputType)
                                            {
                                                case "button":
                                                    return new FCButton();
                                                case "checkbox":
                                                    return new FCCheckBox();
                                                case "datetime":
                                                    return new FCDateTimePicker();
                                                case "radio":
                                                    return new FCRadioButton();
                                                case "range":
                                                    return new FCSpin();
                                                case "text":
                                                    return new FCTextBox();
                                                case "custom":
                                                    return createCustomView(node);
                                            }
                                            break;
                                        }
                                    }
                                }
                                break;
                            case "label":
                                return new FCLabel();
                        }
                        break;
                    }
                case 6:
                    {
                        switch (type)
                        {
                            case "button":
                                return new FCButton();
                            case "column":
                                return new FCGridColumn();
                            case "select":
                                return new FCComboBox();
                            case "custom":
                                return createCustomView(node);
                            case "window":
                                return new FCWindow();
                        }
                        break;
                    }
                case 7:
                    {
                        if (type == "textbox")
                        {
                            return new FCTextBox();
                        }
                        break;
                    }
            }
            if (typeLen > 7)
            {
                switch (type)
                {
                    case "calendar":
                        return new FCCalendar();
                    case "checkbox":
                        return new FCCheckBox();
                    case "combobox":
                        return new FCComboBox();
                    case "datepicker":
                        return new FCDateTimePicker();
                    case "layoutdiv":
                        return new FCLayoutDiv();
                    case "linklabel":
                        return new FCLinkLabel();
                    case "splitlayoutdiv":
                        return new FCSplitLayoutDiv();
                    case "radiobutton":
                        return new FCRadioButton();
                }
            }
            return null;
        }

        /// <summary>
        /// 创建表格列
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void createGridColumns(XmlNode node, FCView view)
        {
            FCGrid grid = view as FCGrid;
            foreach (XmlNode subNode in node.ChildNodes)
            {
                FCView subView = createView(subNode, subNode.Name.ToLower());
                FCGridColumn column = subView as FCGridColumn;
                if (column != null)
                {
                    column.setNative(m_native);
                    grid.addColumn(column);
                }
                setAttributesBefore(subNode, subView);
                readChildNodes(subNode, subView);
                setAttributesAfter(subNode, subView);
                if (subNode.InnerText.Length > 0)
                {
                    column.setText(subNode.InnerText);
                }
                onAddView(subView, subNode);
            }
        }

        /// <summary>
        /// 创建表格行
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void createGridRow(XmlNode node, FCView view)
        {
            FCGrid grid = view as FCGrid;
            FCGridRow row = new FCGridRow();
            grid.addRow(row);
            setAttributesBefore(node, row);
            //单元格
            int col = 0;
            foreach (XmlNode node3 in node.ChildNodes)
            {
                String subNodeName = node3.Name.ToLower();
                String subNodeValue = node3.InnerText;
                if (subNodeName == "cell" || subNodeName == "td")
                {
                    String cellType = "string";
                    if (node3.Attributes != null)
                    {
                        foreach (XmlAttribute attribute in node3.Attributes)
                        {
                            String name = attribute.Name.ToLower();
                            if (name == "type")
                            {
                                cellType = attribute.Value;
                            }
                        }
                    }
                    FCGridCell cell = null;
                    switch (cellType)
                    {
                        case "bool":
                            {
                                cell = new FCGridBoolCell();
                                break;
                            }
                        case "button":
                            {
                                cell = new FCGridButtonCell();
                                break;
                            }
                        case "checkbox":
                            {
                                cell = new FCGridCheckBoxCell();
                                break;
                            }
                        case "combobox":
                            {
                                cell = new FCGridComboBoxCell();
                                break;
                            }
                        case "double":
                            {
                                cell = new FCGridDoubleCell();
                                break;
                            }
                        case "float":
                            {
                                cell = new FCGridFloatCell();
                                break;
                            }
                        case "string":
                            {
                                cell = new FCGridStringCell();
                                break;
                            }
                        case "int":
                            {
                                cell = new FCGridIntCell();
                                break;
                            }
                        case "long":
                            {
                                cell = new FCGridLongCell();
                                break;
                            }
                        case "textbox":
                            {
                                cell = new FCGridTextBoxCell();
                                break;
                            }
                        case "percent":
                            {
                                cell = new FCGridPercentCell();
                                break;
                            }
                    }
                    row.addCell(col, cell);
                    setAttributesBefore(node3, cell);
                    cell.setString(subNodeValue);
                    setAttributesAfter(node3, cell);
                    col++;
                }
            }
            setAttributesAfter(node, row);
        }

        /// <summary>
        /// 创建表格行
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void createGridRows(XmlNode node, FCView view)
        {
            foreach (XmlNode node2 in node.ChildNodes)
            {
                if (node2.Name.ToLower() == "row" || node2.Name.ToLower() == "tr")
                {
                    createGridRow(node2, view);
                }
            }
        }

        /// <summary>
        /// 创建视图框架
        /// </summary>
        /// <param name="hWnd">句柄</param>
        public void createNative()
        {
            m_native = new FCNative();
        }

        /// <summary>
        /// 创建分割布局视图
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void createSplitLayoutSubAttribute(XmlNode node, FCSplitLayoutDiv splitLayoutDiv)
        {
            int oldCount = splitLayoutDiv.getViews().size();
            setAttributesBefore(node, splitLayoutDiv);
            //读取子节点
            readChildNodes(node, splitLayoutDiv);
            ArrayList<FCView> newViews = splitLayoutDiv.getViews();
            if (newViews.size() - oldCount >= 2)
            {
                splitLayoutDiv.setFirstView(newViews.get(newViews.size() - 2));
                splitLayoutDiv.setSecondView(newViews.get(newViews.size() - 1));
            }
            setAttributesAfter(node, splitLayoutDiv);
            //splitLayoutDiv.update();
            onAddView(splitLayoutDiv, node);
        }

        /// <summary>
        /// 创建多页夹的页
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void createTabPage(XmlNode node, FCView view)
        {
            FCTabView tabView = view as FCTabView;
            if (tabView != null)
            {
                FCTabPage tabPage = new FCTabPage();
                tabPage.setNative(m_native);
                tabView.addView(tabPage);
                setAttributesBefore(node, tabPage);
                readChildNodes(node, tabPage);
                setAttributesAfter(node, tabPage);
                onAddView(tabPage, node);
            }
        }

        /// <summary>
        /// 创建树的节点
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        /// <param name="treeNode">树节点</param>
        public virtual void createTreeNode(XmlNode node, FCView view, FCTreeNode treeNode)
        {
            FCTree tree = view as FCTree;
            if (tree != null)
            {
                FCTreeNode appendNode = new FCTreeNode();
                if (treeNode == null)
                {
                    tree.appendNode(appendNode);
                }
                else
                {
                    treeNode.appendNode(appendNode);
                }
                setAttributesBefore(node, appendNode);
                foreach (XmlNode subNode in node.ChildNodes)
                {
                    if (subNode.Name.ToLower() == "node")
                    {
                        createTreeNode(subNode, view, appendNode);
                    }
                }
                setAttributesAfter(node, appendNode);
            }
        }

        /// <summary>
        /// 创建树的节点
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void createTreeNodes(XmlNode node, FCView view)
        {
            foreach (XmlNode subNode in node.ChildNodes)
            {
                createTreeNode(subNode, view, null);
            }
            view.update();
        }

        /// <summary>
        /// 创建子属性
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void createSubAttribute(XmlNode node, FCView view)
        {
            String name = node.Name.ToLower();
            switch (name)
            {
                case "columns":
                    {
                        if (view is FCGrid)
                        {
                            createGridColumns(node, view);
                        }
                        break;
                    }
                //下拉项
                case "item":
                case "option":
                    {
                        //下拉列表
                        if (view is FCComboBox)
                        {
                            FCComboBox comboBox = view as FCComboBox;
                            if (comboBox != null)
                            {
                                createMenuItem(node, comboBox.getDropDownMenu(), null);
                            }
                        }
                        //菜单
                        else if (view is FCMenu)
                        {
                            FCMenu menu = view as FCMenu;
                            if (menu != null)
                            {
                                createMenuItem(node, menu, null);
                            }
                        }
                        break;
                    }
                //树节点
                case "nodes":
                    {
                        if (view is FCTree)
                        {
                            createTreeNodes(node, view);
                        }
                        break;
                    }
                //行
                case "rows":
                    {
                        if (view is FCGrid)
                        {
                            createGridRows(node, view);
                        }
                        break;
                    }
                //多页夹
                case "tabpage":
                    {
                        if (view is FCTabView)
                        {
                            createTabPage(node, view);
                        }
                        break;
                    }
                case "tr":
                    {
                        if (view is FCGrid)
                        {
                            FCGrid grid = view as FCGrid;
                            if (grid.m_columns.size() == 0)
                            {
                                createGridColumns(node, view);
                            }
                            else
                            {
                                createGridRow(node, view);
                            }
                        }
                        break;
                    }
            }
        }

        /// <summary>
        /// 创建用户视图
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="cid">标识</param>
        public virtual FCView createCustomView(XmlNode node)
        {
            //用户视图
            FCView customView = null;
            if (node.Attributes != null)
            {
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    String name = attribute.Name.ToLower();
                    if (name == "cid")
                    {
                        customView = createView(node, attribute.Value);
                        break;
                    }
                }
            }
            if (customView != null)
            {
                //customView.setNative(m_native);
                return customView;
            }
            else
            {
                return new FCView();
            }
        }

        /// <summary>
        /// 销毁方法
        /// </summary>
        public virtual void delete()
        {
            if (!m_isDeleted)
            {
                if (m_name.Length > 0)
                {
                    m_nameXmls.remove(this);
                }
                m_views.clear();
                m_styles.clear();
                m_isDeleted = true;
            }
        }

        /// <summary>
        /// 查找视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>视图</returns>
        public virtual FCView findView(String name)
        {
            foreach (FCView view in m_views)
            {
                if (view.getName() == name)
                {
                    return view;
                }
            }
            return null;
        }

        /// <summary>
        /// 获取属性
        /// </summary>
        /// <param name="node">节点</param>
        /// <returns>属性键值结合</returns>
        public HashMap<String, String> getAttributes(XmlNode node)
        {
            HashMap<String, String> attributes = new HashMap<String, String>();
            if (node.Attributes != null && node.Attributes.Count > 0)
            {
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    String name = attribute.Name.ToLower();
                    String value = attribute.Value;
                    attributes.put(name, value);
                }
            }
            return attributes;
        }

        /// <summary>
        /// 获取所有的视图
        /// </summary>
        /// <returns>视图集合</returns>
        public ArrayList<FCView> getViews()
        {
            return m_views;
        }

        /// <summary>
        /// 获取按钮
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>按钮</returns>
        public FCButton getButton(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCButton;
            }
            return null;
        }

        /// <summary>
        /// 获取图形视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>复选框</returns>
        public FCChart getChart(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCChart;
            }
            return null;
        }

        /// <summary>
        /// 获取复选框
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>复选框</returns>
        public FCCheckBox getCheckBox(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCCheckBox;
            }
            return null;
        }

        /// <summary>
        /// 获取下拉视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>下拉视图</returns>
        public FCComboBox getComboBox(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCComboBox;
            }
            return null;
        }

        /// <summary>
        /// 获取日期视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>日期视图</returns>
        public FCDateTimePicker getDatePicker(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCDateTimePicker;
            }
            return null;
        }

        /// <summary>
        /// 获取图层
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>按钮</returns>
        public FCDiv getDiv(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCDiv;
            }
            return null;
        }

        /// <summary>
        /// 获取表格
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>表格</returns>
        public FCGrid getGrid(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCGrid;
            }
            return null;
        }


        /// <summary>
        /// 获取标签
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>按钮</returns>
        public FCLabel getLabel(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCLabel;
            }
            return null;
        }

        /// <summary>
        /// 获取布局层
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>布局层</returns>
        public FCLayoutDiv getLayoutDiv(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCLayoutDiv;
            }
            return null;
        }

        /// <summary>
        /// 获取名称相似视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>名称相似视图</returns>
        public ArrayList<FCView> getLikeViews(String name)
        {
            ArrayList<FCView> views = new ArrayList<FCView>();
            foreach (FCView view in m_views)
            {
                if (view.getName().StartsWith(name))
                {
                    views.add(view);
                }
            }
            return views;
        }

        /// <summary>
        /// 获取菜单视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>菜单视图</returns>
        public FCMenu getMenu(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCMenu;
            }
            return null;
        }

        /// <summary>
        /// 获取菜单项视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>菜单项视图</returns>
        public FCMenuItem getMenuItem(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCMenuItem;
            }
            return null;
        }

        /// <summary>
        /// 获取单选按钮
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>单选按钮</returns>
        public FCRadioButton getRadioButton(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCRadioButton;
            }
            return null;
        }

        /// <summary>
        /// 获取数值视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>数值视图</returns>
        public FCSpin getSpin(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCSpin;
            }
            return null;
        }

        /// <summary>
        /// 获取分割层
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>分割层</returns>
        public FCSplitLayoutDiv getSplitLayoutDiv(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCSplitLayoutDiv;
            }
            return null;
        }

        /// <summary>
        /// 获取多页夹视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>多页夹视图</returns>
        public FCTabView getTabView(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCTabView;
            }
            return null;
        }

        /// <summary>
        /// 获取夹视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>多页夹视图</returns>
        public FCTabPage getTabPage(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCTabPage;
            }
            return null;
        }

        /// <summary>
        /// 获取文本框
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>多页夹视图</returns>
        public FCTextBox getTextBox(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCTextBox;
            }
            return null;
        }

        /// <summary>
        /// 获取树视图
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>树视图</returns>
        public FCTree getTree(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCTree;
            }
            return null;
        }

        /// <summary>
        /// 获取窗体
        /// </summary>
        /// <param name="name">视图名称</param>
        /// <returns>窗体</returns>
        public FCWindow getWindow(String name)
        {
            FCView view = findView(name);
            if (view != null)
            {
                return view as FCWindow;
            }
            return null;
        }

        /// <summary>
        /// 获取命名的Xml对象
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static FCUIXml getNameXml(String name)
        {
            for (int i = 0; i < m_nameXmls.size(); i++)
            {
                FCUIXml uiXml = m_nameXmls.get(i);
                if (uiXml.m_name == name)
                {
                    return uiXml;
                }
            }
            return null;
        }

        /// <summary>
        /// 判断是否后设置属性
        /// </summary>
        /// <param name="name">属性名称</param>
        /// <returns>是否后设置属性</returns>
        public virtual bool isAfterSetingAttribute(String name)
        {
            int nameLength = name.Length;
            if (nameLength > 0)
            {
                char fir = name[0];
                if (fir == 's' || fir == 'v' || fir == 'c')
                {
                    switch (nameLength)
                    {
                        case 4:
                            if (name == "value")
                            {
                                return true;
                            }
                            break;
                        case 7:
                            if (name == "checked")
                            {
                                return true;
                            }
                            break;
                        case 12:
                            if (name == "selectedtext")
                            {
                                return true;
                            }
                            break;
                        case 13:
                            if (name == "selectedindex"
                                || name == "selectedvalue")
                            {
                                return true;
                            }
                            break;
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 读取文件，加载到视图中
        /// </summary>
        /// <param name="fileName">文件的路径</param>
        /// <param name="view">视图</param>
        public virtual void loadFile(String fileName, FCView view)
        {
            m_views.clear();
            m_styles.clear();
            m_xmlDoc.Load(fileName);

            XmlNode root = m_xmlDoc.DocumentElement;
            foreach (XmlNode node in root.ChildNodes)
            {
                String nodeName = node.Name.ToLower();
                if (nodeName == "body")
                {
                    readBody(node, view);
                }
            }
        }

        /// <summary>
        /// 读取字符串，加载到视图中
        /// </summary>
        /// <param name="xml">字符串</param>
        /// <param name="view">视图</param>
        public virtual void loadXml(String xml, FCView view)
        {
            m_views.clear();
            m_styles.clear();
            m_xmlDoc.LoadXml(xml);
            XmlNode root = m_xmlDoc.DocumentElement;
            foreach (XmlNode node in root.ChildNodes)
            {
                String nodeName = node.Name.ToLower();
                if (nodeName == "body")
                {
                    readBody(node, view);
                }
            }
        }

        /// <summary>
        /// 添加视图
        /// </summary>
        /// <param name="view">视图</param>
        /// <param name="node">节点</param>
        public virtual void onAddView(FCView view, XmlNode node)
        {
            m_views.add(view);
        }

        /// <summary>
        /// 读取文件体
        /// </summary>
        /// <param name="node">XML节点</param>
        /// <param name="view">视图</param>
        public virtual void readBody(XmlNode node, FCView view)
        {
            if (m_allowName)
            {
                HashMap<String, String> attributes = getAttributes(node);
                if (attributes.containsKey("name"))
                {
                    m_name = attributes.get("name");
                    m_nameXmls.add(this);
                }
            }
            foreach (XmlNode subNode in node.ChildNodes)
            {
                readNode(subNode, view);
            }
        }

        /// <summary>
        /// 读取子节点
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="view">视图</param>
        public virtual void readChildNodes(XmlNode node, FCView view)
        {
            if (node.ChildNodes != null && node.ChildNodes.Count > 0)
            {
                foreach (XmlNode subNode in node.ChildNodes)
                {
                    readNode(subNode, view);
                }
            }
        }

        /// <summary>
        /// 读取XML
        /// </summary>
        /// <param name="node">XML节点</param>
        /// <param name="parent">父视图</param>
        public virtual FCView readNode(XmlNode node, FCView parent)
        {
            String type = node.Name.ToLower();
            FCView view = createView(node, type);
            if (view != null)
            {
                view.setNative(m_native);
                if (parent != null)
                {
                    parent.addView(view);
                }
                else
                {
                    m_native.addView(view);
                }
                //前设置属性
                setAttributesBefore(node, view);
                FCSplitLayoutDiv splitLayout = view as FCSplitLayoutDiv;
                if (splitLayout != null)
                {
                    createSplitLayoutSubAttribute(node, splitLayout);
                }
                else
                {
                    //加载子节点
                    readChildNodes(node, view);
                }
                //后设置属性
                setAttributesAfter(node, view);
                if (view.m_views.size() == 0)
                {
                    if (node.InnerText != null && node.InnerText.Length > 0)
                    {
                        view.setText(node.InnerText);
                    }
                }
                view.update();
                onAddView(view, node);
            }
            else
            {
                //创建子属性
                createSubAttribute(node, parent);
            }
            return view;
        }

        /// <summary>
        /// 后设置属性
        /// </summary>
        /// <param name="node">XML节点</param>
        /// <param name="view">属性对象</param>
        public virtual void setAttributesAfter(XmlNode node, FCAttribute view)
        {
            if (node.Attributes != null)
            {
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    String name = attribute.Name.ToLower();
                    String value = attribute.Value;
                    if (isAfterSetingAttribute(name))
                    {
                        view.setAttribute(name, value);
                    }
                }
            }
        }

        /// <summary>
        /// 前设置属性
        /// </summary>
        /// <param name="node">XML节点</param>
        /// <param name="view">属性对象</param>
        public virtual void setAttributesBefore(XmlNode node, FCAttribute view)
        {
            if (node.Attributes != null)
            {
                foreach (XmlAttribute attribute in node.Attributes)
                {
                    String name = attribute.Name.ToLower();
                    String value = attribute.Value;
                    if (!isAfterSetingAttribute(name))
                    {
                        view.setAttribute(name, value);
                    }
                }
            }
        }
    }
}